package com.tech.cloudapp.controller;


import com.tech.cloudapp.biz.service.IBQuestionUserAnswerService;
import com.tech.cloudapp.db.entity.QuestionUserAnswer;
import com.tech.cloudapp.exception.BusinessException;
import com.tech.cloudapp.model.CommonResponseDO;
import com.tech.cloudapp.po.QuestionUserAnswerParamPO;
import com.tech.cloudapp.util.ValidatorUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 用户答题记录表 前端控制器
 * </p>
 *
 * @author mojianyou
 * @since 2025-03-23
 */
@RestController
@RequestMapping("/question-user-answer")
public class QuestionUserAnswerController {

    @Autowired
    private IBQuestionUserAnswerService bQuestionUserAnswerServiceImpl;

    @PostMapping("/saveall")
    public CommonResponseDO saveAll(@RequestBody QuestionUserAnswerParamPO questionUserAnswerParamPO) throws BusinessException, InstantiationException, IllegalAccessException {
        ValidatorUtils.validate(questionUserAnswerParamPO, QuestionUserAnswerParamPO.CheckA.class);
        this.bQuestionUserAnswerServiceImpl.save(questionUserAnswerParamPO);
        return CommonResponseDO.success();
    }

    @PostMapping("/list")
    public CommonResponseDO list(@RequestBody QuestionUserAnswerParamPO questionUserAnswerParamPO)
    {
        ValidatorUtils.validate(questionUserAnswerParamPO, QuestionUserAnswerParamPO.CheckB.class);
        List<QuestionUserAnswer> list = this.bQuestionUserAnswerServiceImpl.list(questionUserAnswerParamPO);
        return CommonResponseDO.success(list);
    }

    @PostMapping("/replayAnswer")
    public CommonResponseDO replayAnswer(@RequestBody QuestionUserAnswerParamPO questionUserAnswerParamPO)
    {
        ValidatorUtils.validate(questionUserAnswerParamPO, QuestionUserAnswerParamPO.CheckB.class);
        this.bQuestionUserAnswerServiceImpl.replayAnswer(questionUserAnswerParamPO);
        return CommonResponseDO.success();
    }


    @PostMapping("/wrongCollect")
    public CommonResponseDO wrongCollect(@RequestBody QuestionUserAnswerParamPO questionUserAnswerParamPO)
    {
        ValidatorUtils.validate(questionUserAnswerParamPO, QuestionUserAnswerParamPO.CheckC.class);
        int len = this.bQuestionUserAnswerServiceImpl.wrongCollect(questionUserAnswerParamPO);
        return CommonResponseDO.success(len);
    }
}

